import { defineStore } from 'pinia';
import { computed, ref } from 'vue';

export const useCounterStore = defineStore('counter', () => {
  // 使用 ref 定义响应式数据
  const count = ref(0);
  const arr = ref({
    a: 1,
    b: 10,
  });

  const doubleCount = computed(() => count.value * 2);
  const arrSum = computed(() => arr.value.a + arr.value.b);

  const increment = () => {
    count.value++;
  };

  const updateArr = (newArr: any) => {
    arr.value = newArr;
  };

  // 返回需要暴露的数据和方法
  return {
    count,
    arr,
    doubleCount,
    arrSum,
    increment,
    updateArr,
  };
});
